﻿using RpcModel;
using Wedonek.RpcStore.Gateway.Interface;
using Wedonek.RpcStore.Service.Interface;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Gateway.Service
{
        internal class RpcControlService : IRpcControlService
        {
                private readonly IRpcControlCollect _RpcControl;
                public RpcControlService (IRpcControlCollect control)
                {
                        this._RpcControl = control;
                }

                public int Add (RpcControl add)
                {
                        this._RpcControl.CheckIsRepeat (add.ServerIp, add.Port);
                        return this._RpcControl.Add (add);
                }

                public void Delete (int id)
                {
                        RpcControlInfo control = this._RpcControl.Get (id);
                        this._RpcControl.Delete (control);
                }

                public RpcControlInfo Get (int id)
                {
                        return this._RpcControl.Get (id);
                }

                public RpcControlInfo[] Query (IBasicPage paging, out long count)
                {
                        return this._RpcControl.Query (paging, out count);
                }

                public void Set (int id, RpcControl set)
                {
                        RpcControlInfo control = this._RpcControl.Get (id);
                        if (control.ServerIp != set.ServerIp || control.Port != control.Port)
                        {
                                this._RpcControl.CheckIsRepeat (set.ServerIp, set.Port);
                        }
                        this._RpcControl.Set (control, set);
                }
        }
}
